/**

 * @author hanzhendong

 * @date 2023/8/23 14:00

 */
// index.js
import Dict from './Dict'

const install = function(Vue) {
  Vue.mixin({
    data() {
      if (
        this.$options.dicts instanceof Array &&
        this.$options.dicts.length > 0
      ) {
        return { dict: {} }
      } else {
        return {}
      }
    },
    created() {
      if (this.$options.dicts instanceof Array) {
        new Dict(this.dict).init(this.$options.dicts, () => {
          this.$nextTick(() => {
            this.$emit('dictReady')
          })
        })
      }
    },
    methods: {
      getDict(items, key, full = false) {
        const dict = items.find(i => i.value === key)
        if(!dict){
          return ''
        }
        return full ? dict :dict.label
      },
    }
  })
}

export default { install }

